/**
 * @author BoLiang
 */
if (typeof accedo === "undefined") {
	accedo = {};
}
if (typeof accedo.achievement === "undefined") {
	accedo.achievement = {};
}

accedo.achievement.achiContShow = {

	oldOnkeydownFunc : null,
	divContCtnNode : null,

	ajaxFunction : function() {
		var xmlHttp = null;
		try {
			xmlHttp = new XMLHttpRequest();
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
				}
			}
		}
		return xmlHttp;
	},

	openPage : function(achi_sn) {
		var xmlReq = this.ajaxFunction();
		xmlReq.open("get", "../Memory/achiContShowServlet?time="
				+ new Date().getTime() + "&achi_sn=" + achi_sn, true);
		xmlReq.send(null);
		xmlReq.onreadystatechange = function() {
			// alert(xmlReq.readyState);
			if (xmlReq.readyState == 4) {
				// alert(xmlReq.status);
				if (xmlReq.status == 200 || xmlReq.status == 304) {
					// alert(xmlReq.responseText);
					var serverDataObj = eval("(" + xmlReq.responseText + ")");
//					alert(serverDataObj.cont); 
					// create achievement content show container
					accedo.achievement.achiContShow.divContCtnNode = document.createElement("div");
					accedo.achievement.achiContShow.divContCtnNode.id = "divAchiShowContent";
					accedo.achievement.achiContShow.divContCtnNode.innerHTML = "<font size=13px color=white>" + serverDataObj.cont + "</font>";
					var bodyNode = document.getElementsByTagName("body")[0];
					bodyNode.appendChild(accedo.achievement.achiContShow.divContCtnNode);

					accedo.achievement.achiContShow.oldOnkeydownFunc = document.onkeydown;
					document.onkeydown = function(e) {
						accedo.achievement.achiContShow.keysControl(e);
					};

				}
			}
		};
	},
	closePage : function() {
		var bodyNode = document.getElementsByTagName("body")[0];
		bodyNode.removeChild(this.divContCtnNode);
		document.onkeydown = this.oldOnkeydownFunc;
	},

	keysControl : function(e) {
		e = window.event || e;
		switch (e.keyCode) {
		// esc button
		case 27:
			this.closePage();
			break;
		default:
			break;
		}
	}

};